//面积(area)
#include <iostream>
#include <cmath>
#include <queue>

using namespace std;
const int MAXN=100;
struct Point
{
    int x,y;
};

int a[MAXN*MAXN+1];
int dir_offset[4][2]={
    {-1,0},{1,0},{0,-1},{0,1}
};
int n;

void search(int x,int y){
    queue<Point> qu;
    Point start={x,y};
    qu.push(start);
    a[x*n+y]=1;
    while (!qu.empty()){
        Point cur=qu.front();
        qu.pop();
        for(int d=0;d<4;d++){
            int newx=cur.x+dir_offset[d][0];
            int newy=cur.y+dir_offset[d][1];
            if (newx<0||newx>=n||newy<0||newy>=n) continue;
            if (a[newx*n+newy]==0){
                Point next={newx,newy};
                qu.push(next);
                a[newx*n+newy]=1;
            }
        }
    }
}

int main(){
    int k=0;
    while(cin>>a[k]){
        k++;
    }
    n=sqrt(k);
    //从四条边缘线检查为0的元素进行广度搜索，遇到1停止，并把搜到的元素都设为1
    for(int y=0;y<n;y++){
        if (a[0*n+y]==0) search(0,y);
        if (a[(n-1)*n+y]==0) search(n-1,y);
    }
    for(int x=0;x<n;x++){
        if (a[x*n+0]==0) search(x,0);
        if (a[x*n+n-1]==0) search(x,n-1);
    } 
    //据统计0的元素个数
    int total=0;
    for(int i=0;i<n*n;i++ ) if (a[i]==0) total++;
    cout<<total; 
}